package com.example.testgit.mapstruct;

import com.example.testgit.VO.ResearchVO;
import com.example.testgit.entity.ResearchDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author: lyh
 * @create: 2023/5/8 11:45
 * Description：
 */
@Mapper
public interface ResearchConverter {
    ResearchConverter INSTANCE = Mappers.getMapper(ResearchConverter.class);

    @Mappings({
            @Mapping(source = "outcomeType", target = "outcomeType", qualifiedByName = "outcomeTrans"),
            @Mapping(source = "acquireTime", target = "acquireTime", dateFormat = "yyyy-MM-dd")
    })
    ResearchVO toVO(ResearchDO researchDO);

    @Mappings({
            @Mapping(source = "outcomeType", target = "outcomeType", qualifiedByName = "outcomeTrans"),
            @Mapping(source = "acquireTime", target = "acquireTime", dateFormat = "yyyy-MM-dd")
    })
    List<ResearchVO> toVOList(List<ResearchDO> researchDOList);

    @Named("outcomeTrans")
    default String outcomeTrans(Integer outcomeType) {
        if (outcomeType.equals(0)) return "论文";
        else if (outcomeType.equals(1)) return "著作";
        else if (outcomeType.equals(2)) return "专利";
        else return "软著";
    }
}
